package vip.meeet.algorithm.str;


public class Num151 {

    public static void main(String[] args) {

        String[] a = {"the sky is blue","  hello world!  ","a good   example"};
        for(String content : a){
            System.out.println(reverseWords(content));
        }
    }

    public static String reverseWords(String s) {
        String[] parts = s.trim().split(" ");
        StringBuffer sb = new StringBuffer();
        for(int i=parts.length-1;i>=0;i--){
            if(parts[i].trim().length() == 0){
                continue;
            }
            sb.append(parts[i]).append(" ");
        }
        sb.toString().substring(0,sb.length() - 1);
        return sb.toString().trim();
    }



}
